import axios from "axios"
import {glistmessage,clearglistmessage,getgooddetailmessage} from "../actionType"

/* redux操作动作 获取商品列表*/
export const getgoodlist = (pagenum) => {
    return (dispatch) => {
        axios.get("https://www.linweiqin.cn/api/public/v1/goods/search", {
            params: {
                pagenum: pagenum
            }
        }).then(res => {
            dispatch({
                type: glistmessage,
                payload: {
                    goodlist:res.data.message.goods
                }
                })
            })

    }
} 
/* 清空商品列表 */
export const cleargoodlist = ()=>{
    return (dispatch) => {
        dispatch({
            type: clearglistmessage,
            payload: {}
        })
    }
}

/* 获取商品详情 */
export const getgooddetail = (goodid) => {
    return (dispatch) => {
        axios.get("https://www.linweiqin.cn/api/public/v1/goods/detail", {
            params: {
                goods_id:goodid
            }
        }).then(res => {
            dispatch({
                type: getgooddetailmessage,
                payload: {
                    message:res.data.message
                }
            })
        })
    }
}